//
//  LoginDataProvider.swift
//  ManBetX
//
//  Created by Cocoa on 2020/4/28.
//  Copyright © 2020 Fullen. All rights reserved.
//

import UIKit

/**
* 本类处理Login页 具体业务网络请求
* Success:返回数据模型 ViewModel 或者 容器<ViewModel>
* Failure:统一返回失败信息
**/

class LoginDataProvider: NSObject {

    //网络请求获取密码加密，用来登录
    class func getEncrypted(succeedBlock: @escaping (_ modulus:String,_ exponent:String) -> Void,failedBlock: @escaping () -> Void){
    
        RequestHelper.get(atPath: "/service/vpkey", withCompletion: { data in
            
            let dataDic = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String]
            
            let modulus = (dataDic?["modulus"] ?? "") as String
            let exponent = (dataDic?["exponent"] ?? "") as String
            
            DispatchQueue.main.async {
                UserDefaults.standard.set(modulus, forKey: DefaultKey.MODULUS)
                UserDefaults.standard.set(exponent, forKey: DefaultKey.EXPONENT)
                
                succeedBlock(modulus,exponent)
            }
        }, withError: { error in
            DispatchQueue.main.async {
                failedBlock()
            }
        })
    }
    
    
}
